﻿Imports System.Data.SqlClient

Public Class clsMONEDAS
    Public Function GUARDA_MONEDA(ByVal MONEDA As String, ByVal TC As Double, ByVal POSICION As Integer, ByVal ESTATUS As Integer, ByVal PAIS As String, ByVal NOMBRE As String, ByVal SIMBOLO As String) As Integer
        Dim sql As String = "Insert Into LISTADO_MONEDAS VALUES(" & _
                           "@MONEDA," & _
                           "@TC_ACTUAL," & _
                           "@POSICION_SIMBOLO," & _
                           "@ESTATUS," & _
                           "@PAIS," & _
                           "@NOMBRE," & _
                           "@SIMBOLO)"



        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = InitialConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("MONEDA", MONEDA)
        Command.Parameters.AddWithValue("TC_ACTUAL", TC)
        Command.Parameters.AddWithValue("POSICION_SIMBOLO", POSICION)
        Command.Parameters.AddWithValue("ESTATUS", ESTATUS)
        Command.Parameters.AddWithValue("PAIS", PAIS)
        Command.Parameters.AddWithValue("NOMBRE", NOMBRE)
        Command.Parameters.AddWithValue("SIMBOLO", SIMBOLO)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
                GUARDA_MONEDA = 1
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
                GUARDA_MONEDA = 2
            End If
        Catch ex As Exception
            GUARDA_MONEDA = -1
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try

    End Function

    Public Function GUARDA_TC_MONEDA(ByVal IDMONEDA As Integer, ByVal FECHA As Date, ByVal TC As Double) As Integer
        Dim sql As String = "Insert Into MONEDAS_TC VALUES(" & _
                           "@IDMONEDA," & _
                           "@FECHA," & _
                           "@TC)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = InitialConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IDMONEDA", IDMONEDA)
        Command.Parameters.AddWithValue("FECHA", FECHA)
        Command.Parameters.AddWithValue("TC", TC)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
                GUARDA_TC_MONEDA = 1
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
                GUARDA_TC_MONEDA = 2
            End If
        Catch ex As Exception
            GUARDA_TC_MONEDA = -1
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try

    End Function
End Class
